<template>
	<view>

		<view class="main-img">
			<image :src="info.image" mode=""></image>
		</view>

		<!-- 详情区域 -->

		<view class="box">
			<view class="boxer">
				<view class="title">{{ info.title }}</view>
				<view class="title2"><text class="dian"></text>活动时间：{{ doreset(info.begintime) }}</view>
				<view class="title2"><text class="dian"></text>截止报名：{{ doreset(info.endtime) }}</view>
				<view class="title2"><text class="dian"></text>活动地点：{{ info.remark }}</view>
				<view class="title2"><text class="dian"></text>联系电话：{{ info.phone }}</view>
				<view class="title2"><text class="dian"></text>报名人数：{{ info.man+info.woman }} （男{{ info.man }} 女{{ info.woman }}) </view>
				<view class="title2"><text class="dian"></text>已报名人数：男{{ info.hasMan }} 女{{ info.hasWoman }} </view>
			</view>

			<rich-text :nodes="info.maincontent"></rich-text>

		</view>

		<!-- <view class="foot">
			<view class="left">活动费用<text class="rmb">¥</text><text class="price">{{ info.cost }}</text></view>
			<view class="right" @tap="getOrder">我要参加</view>
		</view> -->



	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapState(['token'])
		},
		data() {
			return {
				id: '',
				url: '',
				info: {}
			};
		},
		//分享给个人
		onShareAppMessage() {
			return {
				title: '青年交友',
				imageUrl:'https://friend.tanshishang.cn/assets/img/shareImg.png',
				path:'/pages/index/index'
			}
		},
		onLoad(options) {
			if (options.id) {
				this.id = options.id;
			}
			this.url = this.$config.API;

			this.getData();

		},
		methods: {
			//执行我要参加
			// getOrder(){
			// 	uni.showLoading({
			// 		title:'正在报名...'
			// 	});
			// 	setTimeout(()=> {
			// 		this.doResutl();
			// 	},1000)
			// },
			// async doResutl() {
			// 	try {
			// 		let params = {
			// 			token: this.token,
			// 			id: this.info.id
			// 		};
			// 		let res = await this.$request.request.post('/api/active/enlist', params)
			// 		console.log(res);
			// 		if(res.code == 200){
			// 			this.doPay(res.data.orderNo);
			// 		}
					
			// 	} catch (err) {
			// 		this.$request.error(err, this)
			// 	}
			// },
			//调用微信支付
			// async doPay(e){
			// 	try {
			// 		let params = {
			// 			token: this.token,
			// 			id: this.info.id,
			// 			orderNo:e
			// 		};
			// 		let res = await this.$request.request.post('/api/active/ngagement', params)
			// 		console.log(res);
			// 		uni.hideLoading();
			// 		//再发起微信支付
			// 		uni.requestPayment({
			// 			provider: 'wxpay',
			// 			timeStamp: res.data.timeStamp,
			// 			nonceStr: res.data.nonceStr,
			// 			package: res.data.package,
			// 			signType: res.data.signType,
			// 			paySign: res.data.paySign,
			// 			success: res => {
			// 				this.$tips.success("支付成功");
			// 				setTimeout(() => {
			// 					uni.navigateBack({
			// 						delta: 1
			// 					})
			// 				}, 2000);
			// 			},
			// 			fail: (err) => {
			// 				console.log(err);
			// 				this.$tips.fail("支付失败");
			// 			}
			// 		});
			// 	} catch (err) {
			// 		this.$request.error(err, this)
			// 	}
			// },
			//获取数据
			async getData() {
				try {
					let params = {
						token: this.token,
						id: this.id
					};
					let res = await this.$request.request.get('/api/active/detail', params)
					console.log(res);
					if (res.code == 200) {
						this.info = res.data.data;
						this.info.image = this.url+res.data.data.image;
						this.info.cost?this.info.cost = this.info.cost.toFixed(2):'';
					}
				} catch (err) {
					this.$request.error(err, this)
				}
			},
			//转换时间戳
			doreset(e) {
				//转换时间戳
				if ((e + '').length != 13) {
					var date = new Date(e * 1000); //如果date为13位不需要乘1000
					var Y = date.getFullYear() + '-';
					var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
				} else {
					var date = new Date(e); //如果date为13位不需要乘1000
					var Y = date.getFullYear() + '-';
					var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
				}
				return Y + M + D;
			},
		}
	}
</script>

<style lang="scss">
	@import 'friends-detail.scss'
</style>
